package com.nulldev.util.networking.async2.events;

public final class ManualResetEvent {
	private boolean fInitialState;

	public ManualResetEvent(final boolean initialState) {
		this.fInitialState = initialState;
	}

	public synchronized void reset() {
		this.fInitialState = false;
	}

	public synchronized void waitOne() {
		while (!this.fInitialState) {
			try {
				wait();
			} catch (InterruptedException ex) {
			}
		}
	}

	public synchronized void waitOne(final int milliseconds) {
		while (!this.fInitialState) {
			try {
				wait(milliseconds);
			} catch (InterruptedException ex) {
			}
		}
	}

	public synchronized void set() {
		this.fInitialState = true;
		notify();
	}
}
